﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="addpurchase.aspx.cs"  Inherits="StoreWeb.system.purchaseManage.addpurchase" %>

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="../../lib/html5.js"></script>
<script type="text/javascript" src="../../lib/respond.min.js"></script>
<script type="text/javascript" src="../../lib/PIE_IE678.js"></script>
<![endif]-->
<link href="../../css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="../../css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="../../css/style.css" rel="stylesheet" type="text/css" />
<link href="../../lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" />
<link href="../../css/extension.css" rel="stylesheet" />
<link href="../../lib/My97DatePicker/skin/WdatePicker.css" rel="stylesheet" />
<style>
.myTable{ width:100%; min-width:860px; border-top:1px solid #e5e5e5; border-left:1px solid #e5e5e5;}
.myTable th, .myTable td{ height:35px; border-bottom:1px solid #e5e5e5; border-right:1px solid #e5e5e5;}
.myTable th{ font-weight:bold;}
.myTabs th{ text-align:center; background:#f3f3f3; cursor:pointer;}
.myTabs th.active{ background:#fff;}
.myLists{ margin-top:5px; display:none;}
.myLists th, .myLists td{ padding:0 5px;}
.myLists th{ color:#fff; background:#999999;}
.myLists td.tc{ text-align:center;}
.myLists .button{ padding:4px 10px; cursor:pointer;}
.myLists .button,.myLists .number{ vertical-align:middle;}
.myLists .minus{ background:url(/images/minus.jpg) center no-repeat;}
.myLists .plus{ background:url(/images/plus.jpg) center no-repeat;}
.myLists .number{ width:50px; height:22px; line-height:22px; padding:0 5px; text-align:center; border:1px solid #9a9a9a;}
.total-price{ width:100%; padding:5px 0; vertical-align:middle; text-align:right;}
.total-price i.text,.total-price em.price{ font-style:normal; line-height:32px;}
.total-price em.price{ margin-right:10px;}
</style>
<!--[if IE 6]>
<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>采购管理 - 添加采购订单</title>
</head>
<body>
<form method="post" runat="server"   id="formmemberadd">
  <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 采购管理 <span class="c-gray en">&gt;</span> 添加采购订单 <a class="btn btn-success radius r mr-20" style="line-height: 1.6em; margin-top: 3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a></nav>
  <div class="pd-20">
    <table class="myTable myTabs" border="0" cellpadding="0" cellspacing="0">
    	<tr>
        	<%--<th>包装类</th>
            <th>功能类</th>
            <th>配饰类</th>--%>
            <%=myTabs %>
        </tr>
    </table>
    <%--<table class="myTable myLists" border="0" cellpadding="0" cellspacing="0">
    	<tr>
            <th width="15%">产品名称</th>
            <th width="40%">介绍</th>
            <th width="15%">单价</th>
            <th width="15%">数量</th>
            <th width="15%">小计</th>
        </tr>
        <tr class="body">
        	<td>产品名称1<input type="hidden" name="cpmc" value="产品名称1"><input type="hidden" name="cpfl" value="包装类"></td>
            <td>介绍1<input type="hidden" name="cpjs" value="介绍1"></td>
            <td>￥<span class="unit-price">15.00</span><input type="hidden" name="unitprice" value="15.00"></td>
            <td class="tc">
            	<span class="button minus">&nbsp;</span>
                <input class="number" type="text" data-price="15" value="0" name="number" >
                <span class="button plus">&nbsp;</span>
            </td>
            <td>￥<span class="sum-price">0.00</span><input type="hidden" name="sumprice"></td>
        </tr>
        <tr class="body">
        	<td>产品名称2<input type="hidden" name="cpmc" value="产品名称2"><input type="hidden" name="cpfl" value="包装类"></td>
            <td>介绍2<input type="hidden" name="cpjs" value="介绍2"></td>
            <td>￥<span class="unit-price">21.00</span><input type="hidden" name="unitprice" value="21.00"></td>
            <td class="tc">
            	<span class="button minus">&nbsp;</span>
                <input class="number" type="text" data-price="21" value="0" name="number" >
                <span class="button plus">&nbsp;</span>
            </td>
            <td>￥<span class="sum-price">0.00</span><input type="hidden" name="sumprice"></td>
        </tr>
       
    </table>
    <table class="myTable myLists" border="0" cellpadding="0" cellspacing="0">
    	<tr>
            <th width="15%">产品名称</th>
            <th width="40%">介绍</th>
            <th width="15%">单价</th>
            <th width="15%">数量</th>
            <th width="15%">小计</th>
        </tr>
        <tr class="body">
        	<td>产品名称3<input type="hidden" name="cpmc" value="产品名称3"><input type="hidden" name="cpfl" value="功能类"></td>
            <td>介绍3<input type="hidden" name="cpjs" value="介绍3"></td>
            <td>￥<span class="unit-price">31.5</span><input type="hidden" name="unitprice" value="31.5"></td>
            <td class="tc">
            	<span class="button minus">&nbsp;</span>
                <input class="number" type="text" data-price="31.5" value="0" name="number" >
                <span class="button plus">&nbsp;</span>
            </td>
            <td>￥<span class="sum-price">0.00</span><input type="hidden" name="sumprice"></td>
        </tr>
        <tr class="body">
        	<td>产品名称4<input type="hidden" name="cpmc" value="产品名称4"><input type="hidden" name="cpfl" value="功能类"></td>
            <td>介绍4<input type="hidden" name="cpjs" value="介绍4"></td>
            <td>￥<span class="unit-price">48.2</span><input type="hidden" name="unitprice" value="48.2"></td>
            <td class="tc">
            	<span class="button minus">&nbsp;</span>
                <input class="number" type="text" data-price="48.2" value="0" name="number" >
                <span class="button plus">&nbsp;</span>
            </td>
            <td>￥<span class="sum-price">0.00</span><input type="hidden" name="sumprice"></td>
        </tr>
    </table>
    <table class="myTable myLists" border="0" cellpadding="0" cellspacing="0">
    	<tr>
            <th width="15%">产品名称</th>
            <th width="40%">介绍</th>
            <th width="15%">单价</th>
            <th width="15%">数量</th>
            <th width="15%">小计</th>
        </tr>
         <tr class="body">
        	<td>产品名称5<input type="hidden" name="cpmc" value="产品名称5"><input type="hidden" name="cpfl" value="配饰类"></td>
            <td>介绍5<input type="hidden" name="cpjs" value="介绍5"></td>
            <td>￥<span class="unit-price">18.9</span><input type="hidden" name="unitprice" value="18.9"></td>
            <td class="tc">
            	<span class="button minus">&nbsp;</span>
                <input class="number" type="text" data-price="18.9" value="0" name="number" >
                <span class="button plus">&nbsp;</span>
            </td>
            <td>￥<span class="sum-price">0.00</span><input type="hidden" name="sumprice"></td>
        </tr>
        <tr class="body">
        	<td>产品名称6<input type="hidden" name="cpmc" value="产品名称6"><input type="hidden" name="cpfl" value="配饰类"></td>
            <td>介绍6<input type="hidden" name="cpjs" value="介绍6"></td>
            <td>￥<span class="unit-price">59.6</span><input type="hidden" name="unitprice" value="59.6"></td>
            <td class="tc">
            	<span class="button minus">&nbsp;</span>
                <input class="number" type="text" data-price="59.6" value="0" name="number" >
                <span class="button plus">&nbsp;</span>
            </td>
            <td>￥<span class="sum-price">0.00</span><input type="hidden" name="sumprice"></td>
        </tr>
    </table>--%>
      <%=myLists %>
    <div class="total-price"><i class="text">总价： ￥</i><em id="total-price" class="price">0.00</em><input type="hidden" name="totalprice" id="totalprice"><button   ID="btnok" class="btn btn-primary radius" type="submit"><i class="Hui-iconfont"></i>提交订单</button></div>
    <div>
      <%--<input type="hidden" name="hidwhere" id="hidwhere" />--%>
        <asp:HiddenField ID="hidwhere" runat="server" />
      <!-- AspNetPager 7.5 Copyright:2003-2015 Webdiyer (www.webdiyer.com) -->
      <!--记录总数只有一页，AspNetPager已自动隐藏，若需在只有一页数据时显示AspNetPager，请将AlwaysShow属性值设为true！-->
      <!-- AspNetPager 7.5 Copyright:2003-2015 Webdiyer (www.webdiyer.com) -->
    </div>
  </div>
</form>
<%--<script type="text/javascript" src="../../lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="../../lib/layer/1.9.3/layer.js"></script>
<script type="text/javascript" src="../../lib/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="../../js/H-ui.js"></script>
<script type="text/javascript" src="../../js/H-ui.admin.js"></script>--%>
    <script type="text/javascript" src="../../lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="../../lib/layer/1.9.3/layer.js"></script>
    <script type="text/javascript" src="../../lib/Validform/5.3.2/Validform.min.js"></script>
    <script type="text/javascript" src="../../lib/laypage/1.2/laypage.js"></script>
    <script type="text/javascript" src="../../lib/My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="../../js/H-ui.js"></script>
    <script type="text/javascript" src="../../js/H-ui.admin.js"></script>
<script>
    function countSumPrice($price, price) {
        $price
			.text(price)
			.siblings('input[type="hidden"]')
			.val(price);
    }
    function countTotalPrice() {
        var price = 0;
        var $myLists = $('.myLists');
        $.each($('.sum-price', $myLists), function () {
            price += Number($(this).text());
        });
        price = price.toFixed(2);
        $('#total-price')
			.text(price)
			.siblings('input[type="hidden"]')
			.val(price);
    }
    $(function () {
        $.each($('tr.body', $myLists), function () {
            var regexOnlyNumber = /^[1-9][0-9]*$/;
            var $tr = $(this);
            var $unitPrice = $('.unit-price', $tr);
            var $sumPrice = $('.sum-price', $tr);
            var $input = $('.number', $tr)
				.bind('input propertychange blur', function () {
				    var $this = $(this);
				    var val = $this.val();
				    if (!regexOnlyNumber.test(val)) {
				        if ('0' == val)
				            $this.val('0');
				        else
				            $this.val('');
				    }
				})
				.keydown(function (e) {
				    if (!((e.keyCode >= 48 && e.keyCode <= 57)
						|| (e.keyCode >= 96 && e.keyCode <= 105)
						|| e.keyCode == 8 || e.keyCode == 9))
				        return false;
				})
				.keyup(function () {
				    var $this = $(this);
				    var val = $this.val();
				    if (!regexOnlyNumber.test(val))
				        val = '0';
				    var sumPrice = (price * Number(val)).toFixed(2);
				    countSumPrice($sumPrice, (price * Number(val)).toFixed(2));
				    countTotalPrice();
				})
				.bind("paste", function () {
				    return false;
				});
            $('.minus', $tr)
				.click(function () {
				    number--;
				    if (number < 0)
				        number = 0;
				    $input.val(number);
				    countSumPrice($sumPrice, (price * number).toFixed(2));
				    countTotalPrice();
				});
            $('.plus', $tr)
				.click(function () {
				    number++;
				    $input.val(number);
				    countSumPrice($sumPrice, (price * number).toFixed(2));
				    countTotalPrice();
				});
            var price = Number($input.data('price')).toFixed(2);
            var number = Number($input.val());
            $unitPrice.html(price);
            countSumPrice($sumPrice, (price * number).toFixed(2));
        });
        //
        countTotalPrice();
        //
        var $myTabs = $('.myTabs');
        var $myLists = $('.myLists');
        $('th', $myTabs)
			.click(function () {
			    var $this = $(this);
			    var index = $this.index();
			    $this
					.addClass('active')
					.siblings('th')
					.removeClass('active');
			    $myLists
					.eq(index)
					.show()
					.siblings('.myLists')
					.hide();
			})
			.first()
			.addClass('active');
        $myLists
			.first()
			.show();
    });
</script>



<script>

    //$(function () {
    //    $("#formmemberadd").Validform({
    //        tiptype: 2,
    //        btnSubmit: "#btnok",
    //        beforeSubmit: function (curform) {
    //           // alert(document.getElementsByName("purname").length);
    //            //alert($("input[name='purname']").val());
    //            var purnames = "";
    //            $("input[name='purname']").each(
    //            function () {
    //                //alert($(this).val());
    //                purnames += $(this).val()+","
    //            }
    //            )
    //            alert(purnames);
    //            $.post("../../ajax/purchaseManage.aspx", { purname: "" + document.getElementsByName("purname") + "", id: $("#hidid").val() },
    //            function (data) {
    //                //alert(data);
    //                if (data == 1) {
    //                    parent.layer.msg("提交成功", { icon: 1, time: 1000 });
    //                    //window.location.href = "list.aspx";
    //                } else if (data == 2) {
    //                    parent.layer.alert("修改成功", function () {
    //                        parent.location.reload();
    //                    });
    //                } else if (data == 3) {
    //                    parent.location.reload();
    //                } else {
    //                    parent.layer.msg("操作失败");;
    //                }
    //            });
    //            return false;
    //        }
    //    });
    //});


    $("#btnok").click(function () {

        if ($("#totalprice").val() == "0.00") {
            alert("未选购商品");
            return
        }

        $.ajax({
            url: "../../ajax/purchaseManage.aspx",
            //请求的url地址
            data: $('#formmemberadd').serialize(),
            type: "POST",
            //请求方式
            async: true,//这个地方修改
            success: function (data) {
                //alert(data);
                parent.layer.msg("提交成功", { icon: 1, time: 1000 });
                window.location.href = "list.aspx";
            },
            error: function (req) {
                alert(req);
            }
        });
        return false;//这个位置加一个返回失败
    });

</script>
</body>
</html>
